package biz.dewavrin.sipphony.ctl
{
    import mx.collections.errors.ItemPendingError;
    import mx.controls.DataGrid;
    import mx.events.CollectionEvent;
    import mx.events.CollectionEventKind;
    import mx.events.PropertyChangeEvent;
    
    import org.granite.tide.events.TideContextEvent;
    import org.granite.tide.events.TideLoginEvent;
    import org.granite.tide.events.TideResultEvent;
    import org.granite.tide.seam.Context;
    
    
    
    [Bindable]
    public class SearchLocationCtl {
        
        public var locations:DataGrid;
        
        [In]
        public var locationDAO:Object;
        
        
        
        public function SearchLocationCtl(name:String, context:Context):void {
            // Needed for Flex 2
            context.bindIn(name, this, "locationDAO");
            context.addContextEventListener("refresh", refreshHandler);
        }
        
        public function search(text:String):void {
            examplePerson.lastName = text;
            people.refresh();
        }
        
        [Observer("refresh")]
        public function refreshHandler(event:TideContextEvent):void {
            people.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
            people.refresh();
        }
        
        private function collectionChangeHandler(event:CollectionEvent):void {
            people.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
            if (event.kind == CollectionEventKind.REFRESH && personHome.instance != null) {
                persons.selectedItem = personHome.instance;
            }
        }
    }
}
